#ifndef XMLMANAGER_H
#define XMLMANAGER_H

#include "tinyxml.h"
#include "dirmanager.h"
#include "serializer_global.h"
#include "..\SceneData\StaticPropertyNode.h"
#include "..\SceneData\AnimatePropertyNode.h"
#include "..\SceneData\ContainerNode.h"
#include "..\SceneData\PathNode.h"
#include "..\SceneData\PictureNode.h"
#include "..\SceneData\SymbolNode.h"
#include "..\SceneData\RectNode.h"
#include "..\SceneData\MovieClipNode.h"
#include "..\SceneData\EclipseNode.h"
#include "..\SceneData\WordShapeNode.h"
#include "..\SceneData\Ease.h"
#include "..\SceneData\SceneNode.h"
#include <QPair>
#include <QString>
#include <QFile>
using std::exception;

class SERIALIZER_EXPORT XMLManager
{

private:
    QString _errMsg;

    void EncodeDisAttribute(DisplayNode * disp, TiXmlElement * ele);
	void EncodeContAttribute(ContainerNode * cont, TiXmlElement * ele);
	void EncodeShpAttribute(ShapeNode * shp, TiXmlElement * ele);
	void EncodeShpTool(ShapeNode * shp, TiXmlElement * ele);
    TiXmlElement* DecodeDisAttribute(DisplayNode * disp, TiXmlElement * ele);
	void DecodeContAttribute(ContainerNode * cont, TiXmlElement * ele);
	void DecodeShpAttribute(ShapeNode * shp, TiXmlElement * ele);
	void DecodeShpTool(ShapeNode * shp, TiXmlElement * ele);

    bool LinkAtomic(AtomicNode * root, TiXmlElement * ele, QString path);
    bool LinkProperty(PropertyNode * root, TiXmlElement * ele);
    bool LinkSymbol(SymbolNode * root, TiXmlElement * ele, QString path);

    DisplayNode* DecodeDisNode(TiXmlElement* ele, QString type, QString path);
    PropertyNode* DecodeProNode(TiXmlElement* ele, QString type);

public:
    XMLManager();

	~XMLManager(){}

	QString GetErrMessage(){return _errMsg;}

    bool OutputXML(QString name, QString path, ContainerNode* root, SceneNode* scene);
    bool OutputXML(QString name, QString path, ContainerNode* root);

    bool LoadCBP(QString path, QString name, MovieClipNode*& movie, SceneNode*& scene);
    bool LoadBLK(QString path, QString name, MovieClipNode*& movie);
};

#endif // XMLMANAGER_H
